package com.zhuoyue.common.dto;

import com.zhuoyue.common.constant.ResultCode;
import lombok.*;


import java.io.Serializable;

/**
 * 统一返回类型
 * @author wjming
 * @ClassName: ActionResult
 * @Description: action层向页面返回的信息(原商品通用的返回)
 * @date 2013-11-20 上午11:27:04
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ControllerResult<T> implements Serializable {

    private static final long serialVersionUID = 161389017990134747L;

    /**
     * 操作结果标志
     */
    private boolean success;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回对象
     */
    private Object dataObject;

    /**
     * 消息code
     */
    private String msgCode;


    /**
     * 返回数据dataObject
     *
     * @param dataObject
     * @return
     */
    public static ControllerResult toReturnDataSuccess(String msg, Object dataObject) {
        return new ControllerResult(true, msg, dataObject, ResultCode.SUCCESS);

    }

    /**
     * 不返回数据只返回msg
     *
     * @param msg
     * @return
     */
    public static ControllerResult toReturnMessageSuccess(String msg) {
        return new ControllerResult(true, msg, null, ResultCode.SUCCESS);
    }

    /**
     * 不返回数据只返回msg
     *
     * @param msg
     * @return
     */
    public static ControllerResult toReturnMessageOtherCode(String msg, String code) {
        return new ControllerResult(true, msg, null, code);
    }

    public static ControllerResult toSysErrorFail(String msg) {
        return new ControllerResult(false, msg, null, ResultCode.SYS_ERROR);
    }

    /**
     * 参数错误
     *
     * @param msg
     * @return
     */
    public static ControllerResult toParamFail(String msg) {
        return new ControllerResult(false, msg, null, ResultCode.PARAM_ERROR);
    }

    /**
     * 查询无数据
     *
     * @param msg
     * @return
     */
    public static ControllerResult toNoDataFail(String msg) {
        return new ControllerResult(false, msg, null, ResultCode.NO_DATA);
    }

    /**
     * 自定义失败返回
     *
     * @param msg
     * @param msgCode
     * @return
     */
    public static ControllerResult toOtherFail(String msg, String msgCode) {
        return new ControllerResult(false, msg, null, msgCode);
    }

    public static ControllerResult toFail(String msg) {
        return new ControllerResult(false, msg, null, ResultCode.FAIL);
    }

    /**
     * token过期
     *
     * @param msg
     * @return
     */
    public static ControllerResult toTokenExpiret(String msg) {
        return new ControllerResult(false, msg, null, ResultCode.TOKEN_EXPIRET);
    }


}
